package com.demo.web.response;

import java.util.Collection;

import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("分页数据")
public class PageBean<T> {

    @ApiModelProperty(value = "数据列表")
    private Collection<T> records;

    @ApiModelProperty(value = "总数")
    private int total = 0;

    @ApiModelProperty(value = "每页大小")
    private int size = 10;

    @ApiModelProperty(value = "总页数")
    private int pages = 0;

    @ApiModelProperty(value = "当前页")
    private int current = 1;

    public PageBean() {}

    public PageBean(Collection<T> records, int total, int size, int pages, int current) {
        this.records = records;
        this.total = total;
        this.current = current;
        this.size = size;
        this.pages = pages;
    }

    public PageBean(IPage<T> page) {
        this(page.getRecords(), (int)page.getTotal(), (int)page.getSize(),
            (int)page.getCurrent(), (int)page.getPages());
    }

}
